package com.ysu.yybk.controller;

import com.ysu.yybk.VO.ResultVO;
import com.ysu.yybk.enums.ResultEnum;
import com.ysu.yybk.exception.YybkException;
import com.ysu.yybk.service.CourseService;
import com.ysu.yybk.util.ResultVOUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/teacher/course")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @PostMapping("/addStudent")
    public ResultVO addStudent(@RequestParam("studentId") String studentId,
                               @RequestParam("courseId") String courseId){
        if (StringUtils.isEmpty(studentId) || StringUtils.isEmpty(courseId)) {
            throw new YybkException(ResultEnum.PARAM_ERROR);
        }
        courseService.addStudent(studentId, courseId);
        return ResultVOUtil.success();
    }

    @PostMapping("/deleteStudent")
    public ResultVO deleteStudent(@RequestParam("studentId") String studentId,
                                  @RequestParam("courseId") String courseId) {
        if (StringUtils.isEmpty(studentId) || StringUtils.isEmpty(courseId)) {
            throw new YybkException(ResultEnum.PARAM_ERROR);
        }
        courseService.deleteStudent(studentId, courseId);
        return ResultVOUtil.success();
    }
}
